/*
 * TimeLimit.h
 *
 *  Created on: Apr 2, 2014
 *      Author: ik
 */

#ifndef TIMELIMIT_H_
#define TIMELIMIT_H_

#include <time.h>

class TimeLimit
{
    public:
        static TimeLimit& getInstance()
        {
    	static TimeLimit    instance; // Guaranteed to be destroyed.
    						  // Instantiated on first use.
    	return instance;
        }
        bool limitReached();
        static constexpr double MAX_SECONDS = 300.0;
    private:
        clock_t start;
        TimeLimit() {
        	start =  clock ();
        };                   // Constructor? (the {} brackets) are needed here.
        // Dont forget to declare these two. You want to make sure they
        // are unaccessable otherwise you may accidently get copies of
        // your singleton appearing.
        TimeLimit(TimeLimit const&);              // Don't Implement
        void operator=(TimeLimit const&); // Don't implement
};


//inline static TimeLimit& TimeLimit::getInstance()
//{
//	static TimeLimit    instance; // Guaranteed to be destroyed.
//						  // Instantiated on first use.
//	return instance;
//}

inline bool TimeLimit::limitReached(){

	return ((double)(clock() - start) / (double)CLOCKS_PER_SEC) > MAX_SECONDS;
}

#endif /* TIMELIMIT_H_ */
